package com.webapp.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.log4j.Logger;

import com.els.util.PropertyHelper;

public class AbstractDAO {
	protected Logger logger=Logger.getLogger(this.getClass());
	private PropertyHelper ph=new PropertyHelper(null);
	private String url=ph.getProperties("jdbc.url");
	private String username=ph.getProperties("jdbc.username");
	private String password=ph.getProperties("jdbc.password");
	private String driverClassName=ph.getProperties("jdbc.driverClassName");
	protected Connection con;
	protected Statement state;

	protected void getConnection() throws SQLException, ClassNotFoundException {
		Class.forName(driverClassName);
		con=DriverManager.getConnection(url,username,password);
		state=con.createStatement();
	}
	protected void closeConnection() throws SQLException {
		state.close();
		con.close();
	}	
	public static void main(String[] args) {
		AbstractDAO a = new AbstractDAO();
		String sql="select " +
				"jd.id," +
				"s.brand," +
				"s.series," +
				"jd.choose," +
				"jd.gender," +
				"jd.category," +
				"jd.func," +
				"jd.crowd," +
				"'JD' as platform " +
				"from jdproduct as jd " +
				"LEFT OUTER JOIN jdseries as s ON jd.series_id=s.id";
		try {
			a.getConnection();
			ResultSet rs = a.state.executeQuery(sql);
			while (rs.next()) {
				for(int i=0;i<9;i++){
					System.out.print(rs.getString(i+1));
					System.out.print(",");
				}
				System.out.println("==========");
			}
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			
		}
	}
}
